package EvernoteTwo;

import java.io.*;
import java.util.*;

public class Solution {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        
        if(n > 0){
        	HashMap<String, Integer> wordHash = new HashMap<String, Integer>();
        	
        	//Retrieve the words.
	        for(int i = 0; i < n; i++)
	        {
	        	String word = br.readLine().trim();
	        	
	        	//Update the word in the hash.
	        	if(wordHash.containsKey(word))
	        	{
	        		int occur = wordHash.get(word);
	        		wordHash.put(word, occur + 1);
	        	}
	        	else
	        	{
	        		wordHash.put(word, 1);
	        	}
	        }
	        
	        //Retrieve k.
	        line = br.readLine();
	        int k = Integer.parseInt(line);
	        
	        //Print out the words.
	        printList(getWords(wordHash, k));
	        
	        //Close the stream.
	        br.close();  
        }
	}
	
	
	static List<String> getWords(HashMap<String, Integer> hash, int k)
	{
		List<String> ret = new ArrayList<String>();
		
		//Get the top k occurrences and a list of unique words.
        Set<Integer> occurrences = getUniqueValues(hash.values());
        List<String> words = new ArrayList<String>(hash.keySet());
        Collections.sort(words);
        
        //Get the top occurring words.
        int count = 0;
        for(Iterator<Integer> iter = occurrences.iterator(); iter.hasNext();)
        {
        	int val = iter.next();
        	
    		//Get all words that occur "val" times.
    		for(Iterator<String> wordIter = words.iterator(); wordIter.hasNext();)
    		{
    			String word = wordIter.next();
    			int occur = (hash.get(word)!=null) ? hash.get(word) : 0;
    			if(occur==val)
    			{
    				if(count < k)
    	        	{
	    				ret.add(word);
	    				count++;
    	        	}
    			}
    		}
    		
    		
    	
        }
        
        return ret;
	}
	
	static Set<Integer> getUniqueValues(Collection<Integer> set)
	{
		Set<Integer> vals = new TreeSet<Integer>(Collections.reverseOrder());
		HashSet<Integer> hash = new HashSet<Integer>();
		
		for(Iterator<Integer> iter = set.iterator(); iter.hasNext();)
		{
			int val = iter.next();
			
			if(!hash.contains(val))
			{
				hash.add(val);
				vals.add(val);
			}
		}
		
		return vals;
	}
	
	static void printList(List<String> list)
	{
		for(Iterator<String> iter = list.iterator(); iter.hasNext();)
		{
			String word = iter.next();
			System.out.println(word);
		}
	}
	
	static void printSet(Set<String> list)
	{
		for(Iterator<String> iter = list.iterator(); iter.hasNext();)
		{
			String word = iter.next();
			System.out.println(word);
		}
	}
}
